<?php
  class Keke_witkey_a_comment_class{
        public $_db;
        public $_tablename;
	    public $_dbop;
   	 	      public $_c_id;  
		 public $_zp_id; 
		 public $_author_id; 
		 public $_c_time; 
		 public $_c_content;  
		 public $_author_name; 

	    public $_cache_config = array ('is_cache' => 0, 'time' => 0 );
	    public $_replace=0;  
	    public $_where;      
	     function  keke_witkey_a_comment_class(){ 
			 $this->_db = new db_factory ( );
			 $this->_dbop = $this->_db->create(DBTYPE);
			 $this->_tablename = TABLEPRE."witkey_a_comment";
		 }
	    
	    		public function getC_id(){
			 return $this->_c_id ;
		}
		public function getZp_id(){
			 return $this->_zp_id ;
		}
		public function getAuthor_id(){
			 return $this->_author_id ;
		}
		public function getC_time(){
			 return $this->_c_time ;
		}
		public function getC_content(){
			 return $this->_c_content ;
		}
		public function getAuthor_name(){
			 return $this->_author_name ;
		}
		
		public function getWhere(){
			 return $this->_where ;
		}
		public function getCache_config() {
			return $this->_cache_config;
		}

	    		public function setC_id($value){ 
			 $this->_c_id = $value;
		}
		public function setZp_id($value){ 
			 $this->_zp_id = $value;
		}
		public function setAuthor_id($value){ 
			 $this->_author_id = $value;
		}
		public function setC_time($value){ 
			 $this->_c_time = $value;
		}
		public function setC_content($value){ 
			 $this->_c_content = $value;
		}
		public function setAuthor_name($value){ 
			 $this->_author_name = $value;
		}
		
		public function setWhere($value){ 
			 $this->_where = $value;
		}
		public function setCache_config($_cache_config) {
			 $this->_cache_config = $_cache_config; 
		}

	    
    	   public  function __set($property_name, $value) {

		 		$this->$property_name = $value; 

			}

			public function __get($property_name) { 

				if (isset ( $this->$property_name )) { 

					return $this->$property_name; 

				} else { 

					return null; 

				} 

			}

    	
	    /**
		 * insert into  keke_witkey_a_comment  ,or add new record
		 * @return int last_insert_id
		 */
		function create_keke_witkey_a_comment(){
		 		 $data =  array(); 

					if(!is_null($this->_c_id)){ 
				 $data['c_id']=$this->_c_id;
			}
			if(!is_null($this->_zp_id)){ 
				 $data['zp_id']=$this->_zp_id;
			}
			if(!is_null($this->_author_id)){ 
				 $data['author_id']=$this->_author_id;
			}
			if(!is_null($this->_c_time)){ 
				 $data['c_time']=$this->_c_time;
			}
			if(!is_null($this->_c_content)){ 
				 $data['c_content']=$this->_c_content;
			}
			if(!is_null($this->_author_name)){ 
				 $data['author_name']=$this->_author_name;
			}
			//var_dump($data);die();
			 return $this->_c_id = $this->_db->inserttable($this->_tablename,$data,1,$this->_replace); 
		 } 

	    /**
		 * edit table keke_witkey_a_comment
		 * @return int affected_rows
		 */
		function edit_keke_witkey_a_comment(){ 
		 		 $data =  array(); 
 
					if(!is_null($this->_c_id)){ 
				 $data['c_id']=$this->_c_id;
			}
			if(!is_null($this->_zp_id)){ 
				 $data['zp_id']=$this->_zp_id;
			}
			if(!is_null($this->_author_id)){ 
				 $data['author_id']=$this->_author_id;
			}
			if(!is_null($this->_c_time)){ 
				 $data['c_time']=$this->_c_time;
			}
			if(!is_null($this->_c_content)){ 
				 $data['c_content']=$this->_c_content;
			}
			if(!is_null($this->_author_name)){ 
				 $data['author_name']=$this->_author_name;
			}
			

			if($this->_where){ 
				 return $this->_db->updatetable($this->_tablename,$data,$this->getWhere()); 
			 } 
			 else{ 
				 $where = array('c_id' => $this->_c_id); 
				 return $this->_db->updatetable($this->_tablename,$data,$where); 
			} 
		 } 

	    /**
		 * query table: keke_witkey_a_comment,if isset where return where record,else return all record
		 * @return array 
		 */
		function query_keke_witkey_a_comment($is_cache=0, $cache_time=0){ 
			 if($this->_where){ 
				 $sql = "select * from $this->_tablename where ".$this->_where; 
			 } 
			 else{ 
				 $sql = "select * from $this->_tablename"; 
			 } 
			
			if ($is_cache) {
			 $this->_cache_config ['is_cache'] = $is_cache;
			}
			if ($cache_time) {
			 $this->_cache_config ['time'] = $cache_time;
			 }
			 if ($this->_cache_config ['is_cache']) {
			     if (CACHE_TYPE) {
					 $keke_cache = new keke_cache_class ( CACHE_TYPE );
					 $id = $this->_tablename . ($this->_where?"_" .substr(md5 ( $this->_where ),0,6):'');
						$data = $keke_cache->get ( $id );
							if ($data) {
								return $data; 
							} else { 
								$res = $this->_dbop->query ( $sql ); 
								$keke_cache->set ( $id, $res,$this->_cache_config['time'] ); 
					 			$this->_where = ""; 
								return $res;
 							} 
						} 
			 }else{
			 	$this->_where = ""; 
				return  $this->_dbop->query ( $sql );
 			 }
		 } 

	    /**
		 * query count keke_witkey_a_comment records,if iset where query by where 
		 * @return int count records
		 */
		function count_keke_witkey_a_comment(){ 
		  //echo $this->_where;die();
			 if($this->_where){ 
				 $sql = "select count(*) as count from $this->_tablename where ".$this->_where; 
                 //echo $sql;die();
			 } 
			 else{ 
				 $sql = "select count(*) as count from $this->_tablename"; 
			 } 
			 $this->_where = ""; 
			 return $this->_dbop->getCount($sql); 
		 } 

	    /**
		 * delete table keke_witkey_a_comment, if isset where delete by where 
		 * @return int deleted affected_rows 
		 */
		function del_keke_witkey_a_comment(){ 
			 if($this->_where){ 
				 $sql = "delete from $this->_tablename where ".$this->_where; 
			 } 
			 else{ 
				 $sql = "delete from $this->_tablename where zp_id = $this->_zp_id "; 
			 } 
			 $this->_where = ""; 
			 return $this->_dbop->execute($sql); 
		 } 

	   
	    
	    
   }
 ?>